package cc.fs.study.pulltorefash;

import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

import cc.fs.study.R;
import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrDefaultHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;

public class PullToRefashActivity extends AppCompatActivity {

    PtrFrameLayout ptrFrame;
    RecyclerView recyclerView;
    MyAdapter myAdapter;
    List<String> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pull_to_refash);

        list = new ArrayList<>();
        list.add("北京");
        list.add("上海");
        list.add("天津");
        list.add("河南");
        list.add("湖北");
        list.add("湖南");
        list.add("甘肃");
        list.add("广东");
        list.add("山东");
        list.add("河北");
        list.add("深圳");
        list.add("西藏");
        list.add("青海");
        list.add("黑龙江");
        list.add("山西");
        list.add("重庆");
        list.add("四川");
        list.add("海南");
        list.add("福建");
        list.add("内蒙古");
        list.add("吉林");
        list.add("长春");
        list.add("江苏");
        list.add("浙江");

        ptrFrame = (PtrFrameLayout) findViewById(R.id.frameLayout);
//        ptrFrame.setLastUpdateTimeRelateObject(this);
        ptrFrame.setPtrHandler(new PtrDefaultHandler() {
            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {
                frame.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        ptrFrame.refreshComplete();
                    }
                }, 1500);
            }

            @Override
            public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
                return true;
            }
        });

        myAdapter = new MyAdapter(list);
        recyclerView = (RecyclerView)findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(myAdapter);

    }
}
